home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / drivers / toki.c < prev    next >
C/C++ Source or Header  |  2000-05-04  |  24KB  |  691 lines

  1. /***************************************************************************
  2.  
  3. Toki
  4.  
  5. driver by Jarek Parchanski
  6.  
  7. ***************************************************************************/
  8. #include "driver.h"
  9. #include "vidhrdw/generic.h"
  10. #include "cpu/z80/z80.h"
  11.  
  12.  
  13. static unsigned char *ram;
  14. extern unsigned char *toki_foreground_videoram;
  15. extern unsigned char *toki_background1_videoram;
  16. extern unsigned char *toki_background2_videoram;
  17. extern unsigned char *toki_sprites_dataram;
  18. extern unsigned char *toki_scrollram;
  19.  
  20. extern size_t toki_foreground_videoram_size;
  21. extern size_t toki_background1_videoram_size;
  22. extern size_t toki_background2_videoram_size;
  23. extern size_t toki_sprites_dataram_size;
  24.  
  25. int toki_interrupt(void);
  26. int  toki_vh_start(void);
  27. void toki_vh_stop(void);
  28. void toki_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh);
  29. READ_HANDLER( toki_foreground_videoram_r );
  30. WRITE_HANDLER( toki_foreground_videoram_w );
  31. READ_HANDLER( toki_background1_videoram_r );
  32. WRITE_HANDLER( toki_background1_videoram_w );
  33. READ_HANDLER( toki_background2_videoram_r );
  34. WRITE_HANDLER( toki_background2_videoram_w );
  35. WRITE_HANDLER( toki_linescroll_w );
  36.  
  37.  
  38. static READ_HANDLER( toki_ports_r )
  39. {
  40.     switch(offset)
  41.     {
  42.         case 0:
  43.             return input_port_3_r(0) + (input_port_4_r(0) << 8);
  44.         case 2:
  45.             return input_port_1_r(0) + (input_port_2_r(0) << 8);
  46.         case 4:
  47.             return input_port_0_r(0);
  48.         default:
  49.             return 0;
  50.     }
  51. }
  52.  
  53. WRITE_HANDLER( toki_soundcommand_w )
  54. {
  55.     soundlatch_w(0,data & 0xff);
  56.     cpu_cause_interrupt(1,0xff);
  57. }
  58.  
  59. static int msm5205next;
  60.  
  61. void toki_adpcm_int (int data)
  62. {
  63.     static int toggle=0;
  64.  
  65.     MSM5205_data_w (0,msm5205next);
  66.     msm5205next>>=4;
  67.  
  68.     toggle ^= 1;
  69.     if (toggle)
  70.         cpu_cause_interrupt(1,Z80_NMI_INT);
  71. }
  72.  
  73. WRITE_HANDLER( toki_adpcm_control_w )
  74. {
  75.     int bankaddress;
  76.     unsigned char *RAM = memory_region(REGION_CPU2);
  77.  
  78.  
  79.     /* the code writes either 2 or 3 in the bottom two bits */
  80.     bankaddress = 0x10000 + (data & 0x01) * 0x4000;
  81.     cpu_setbank(1,&RAM[bankaddress]);
  82.  
  83.     MSM5205_reset_w(0,data & 0x08);
  84. }
  85.  
  86. WRITE_HANDLER( toki_adpcm_data_w )
  87. {
  88.     msm5205next = data;
  89. }
  90.  
  91. static READ_HANDLER( pip_r )
  92. {
  93.     return 0xffff;
  94. }
  95.  
  96.  
  97. static struct MemoryReadAddress readmem[] =
  98. {
  99.     { 0x000000, 0x05ffff, MRA_ROM },
  100.     { 0x060000, 0x06dfff, MRA_BANK2 },
  101.     { 0x06e000, 0x06e7ff, paletteram_word_r },
  102.     { 0x06e800, 0x06efff, toki_background1_videoram_r },
  103.     { 0x06f000, 0x06f7ff, toki_background2_videoram_r },
  104.     { 0x06f800, 0x06ffff, toki_foreground_videoram_r },
  105.     { 0x072000, 0x072001, watchdog_reset_r },    /* probably */
  106.     { 0x0c0000, 0x0c0005, toki_ports_r },
  107.     { 0x0c000e, 0x0c000f, pip_r },    /* sound related, if we return 0 the code writes */
  108.                                     /* the sound command quickly followed by 0 and the */
  109.                                     /* sound CPU often misses the command. */
  110.     { -1 }  /* end of table */
  111. };
  112.  
  113. static struct MemoryWriteAddress writemem[] =
  114. {
  115.     { 0x000000, 0x05ffff, MWA_ROM },
  116.     { 0x060000, 0x06dfff, MWA_BANK2, &ram },
  117.     { 0x06e000, 0x06e7ff, paletteram_xxxxBBBBGGGGRRRR_word_w, &paletteram },
  118.     { 0x06e800, 0x06efff, toki_background1_videoram_w, &toki_background1_videoram, &toki_background1_videoram_size },
  119.     { 0x06f000, 0x06f7ff, toki_background2_videoram_w, &toki_background2_videoram, &toki_background2_videoram_size },
  120.     { 0x06f800, 0x06ffff, toki_foreground_videoram_w, &toki_foreground_videoram, &toki_foreground_videoram_size },
  121.     { 0x071000, 0x071001, MWA_NOP },    /* sprite related? seems another scroll register; */
  122.                                         /* gets written the same value as 75000a (bg2 scrollx) */
  123.     { 0x071804, 0x071807, MWA_NOP },    /* sprite related; always 01be0100 */
  124.     { 0x07180e, 0x071e45, MWA_BANK3, &toki_sprites_dataram, &toki_sprites_dataram_size },
  125.     { 0x075000, 0x075001, toki_soundcommand_w },
  126.     { 0x075004, 0x07500b, MWA_BANK4, &toki_scrollram },
  127.     { 0x0a002a, 0x0a002d, toki_linescroll_w },    /* scroll register used to waggle the title screen */
  128.     { -1 }  /* end of table */
  129. };
  130.  
  131. static struct MemoryReadAddress sound_readmem[] =
  132. {
  133.     { 0x0000, 0x7fff, MRA_ROM },
  134.     { 0x8000, 0xbfff, MRA_BANK1 },
  135.     { 0xec00, 0xec00, YM3812_status_port_0_r },
  136.     { 0xf000, 0xf7ff, MRA_RAM },
  137.     { 0xf800, 0xf800, soundlatch_r },
  138.     { -1 }  /* end of table */
  139. };
  140.  
  141. static struct MemoryWriteAddress sound_writemem[] =
  142. {
  143.     { 0x0000, 0xbfff, MWA_ROM },
  144.     { 0xe000, 0xe000, toki_adpcm_control_w },    /* MSM5205 + ROM bank */
  145.     { 0xe400, 0xe400, toki_adpcm_data_w },
  146.     { 0xec00, 0xec00, YM3812_control_port_0_w },
  147.     { 0xec01, 0xec01, YM3812_write_port_0_w },
  148.     { 0xec08, 0xec08, YM3812_control_port_0_w },    /* mirror address, it seems */
  149.     { 0xec09, 0xec09, YM3812_write_port_0_w },    /* mirror address, it seems */
  150.     { 0xf000, 0xf7ff, MWA_RAM },
  151.     { -1 }  /* end of table */
  152. };
  153.  
  154.  
  155.  
  156. INPUT_PORTS_START( toki )
  157.     PORT_START    /* IN0 */
  158.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )
  159.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN2 )
  160.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_COIN3 )
  161.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START1 )
  162.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_START2 )
  163.     PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_UNKNOWN )
  164.     PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_UNKNOWN )
  165.     PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_UNKNOWN )
  166.  
  167.     PORT_START    /* IN1 */
  168.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY )
  169.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY )
  170.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY )
  171.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY )
  172.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 )
  173.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 )
  174.     PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_UNKNOWN )
  175.     PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_UNKNOWN )
  176.  
  177.     PORT_START    /* IN2 */
  178.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY | IPF_COCKTAIL )
  179.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY | IPF_COCKTAIL )
  180.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY | IPF_COCKTAIL )
  181.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | IPF_COCKTAIL )
  182.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_COCKTAIL )
  183.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_COCKTAIL )
  184.     PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_UNKNOWN )
  185.     PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_UNKNOWN )
  186.  
  187.     PORT_START      /* DSW0 */
  188.     PORT_DIPNAME( 0x1F, 0x1F, DEF_STR( Coinage ) )
  189.     PORT_DIPSETTING(    0x15, DEF_STR( 6C_1C ) )
  190.     PORT_DIPSETTING(    0x17, DEF_STR( 5C_1C ) )
  191.     PORT_DIPSETTING(    0x19, DEF_STR( 4C_1C ) )
  192.     PORT_DIPSETTING(    0x1B, DEF_STR( 3C_1C ) )
  193.     PORT_DIPSETTING(    0x03, DEF_STR( 8C_3C ) )
  194.     PORT_DIPSETTING(    0x1D, DEF_STR( 2C_1C ) )
  195.     PORT_DIPSETTING(    0x05, DEF_STR( 5C_3C ) )
  196.     PORT_DIPSETTING(    0x07, DEF_STR( 3C_2C ) )
  197.     PORT_DIPSETTING(    0x1F, DEF_STR( 1C_1C ) )
  198.     PORT_DIPSETTING(    0x09, DEF_STR( 2C_3C ) )
  199.     PORT_DIPSETTING(    0x13, DEF_STR( 1C_2C ) )
  200.     PORT_DIPSETTING(    0x11, DEF_STR( 1C_3C ) )
  201.     PORT_DIPSETTING(    0x0F, DEF_STR( 1C_4C ) )
  202.     PORT_DIPSETTING(    0x0D, DEF_STR( 1C_5C ) )
  203.     PORT_DIPSETTING(    0x0B, DEF_STR( 1C_6C ) )
  204.     PORT_DIPSETTING(    0x1E, "A 1/1 B 1/2" )
  205.     PORT_DIPSETTING(    0x14, "A 2/1 B 1/3" )
  206.     PORT_DIPSETTING(    0x0A, "A 3/1 B 1/5" )
  207.     PORT_DIPSETTING(    0x00, "A 5/1 B 1/6" )
  208.     PORT_DIPSETTING(    0x01, DEF_STR( Free_Play ) )
  209.     PORT_DIPNAME( 0x20, 0x20, "Joysticks" )
  210.     PORT_DIPSETTING(    0x20, "1" )
  211.     PORT_DIPSETTING(    0x00, "2" )
  212.     PORT_DIPNAME( 0x40, 0x40, DEF_STR( Cabinet ) )
  213.     PORT_DIPSETTING(    0x40, DEF_STR( Upright ) )
  214.     PORT_DIPSETTING(    0x00, DEF_STR( Cocktail ) )
  215.     PORT_DIPNAME( 0x80, 0x80, DEF_STR( Flip_Screen ) )
  216.     PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
  217.     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
  218.  
  219.     PORT_START    /* DSW1 */
  220.     PORT_DIPNAME( 0x03, 0x03, DEF_STR( Lives ) )
  221.     PORT_DIPSETTING(    0x02, "2" )
  222.     PORT_DIPSETTING(    0x03, "3" )
  223.     PORT_DIPSETTING(    0x01, "5" )
  224.     PORT_BITX( 0,       0x00, IPT_DIPSWITCH_SETTING | IPF_CHEAT, "Infinite", IP_KEY_NONE, IP_JOY_NONE )
  225.     PORT_DIPNAME( 0x0C, 0x0C, DEF_STR( Bonus_Life ) )
  226.     PORT_DIPSETTING(    0x08, "50000 150000" )
  227.     PORT_DIPSETTING(    0x00, "70000 140000 210000" )
  228.     PORT_DIPSETTING(    0x0C, "70000" )
  229.     PORT_DIPSETTING(    0x04, "100000 200000" )
  230.     PORT_DIPNAME( 0x30, 0x30, DEF_STR( Difficulty ) )
  231.     PORT_DIPSETTING(    0x20, "Easy" )
  232.     PORT_DIPSETTING(    0x30, "Medium" )
  233.     PORT_DIPSETTING(    0x10, "Hard" )
  234.     PORT_DIPSETTING(    0x00, "Hardest" )
  235.     PORT_DIPNAME( 0x40, 0x40, "Allow Continue" )
  236.     PORT_DIPSETTING(    0x00, DEF_STR( No ) )
  237.     PORT_DIPSETTING(    0x40, DEF_STR( Yes ) )
  238.     PORT_DIPNAME( 0x80, 0x80, DEF_STR( Demo_Sounds ) )
  239.     PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
  240.     PORT_DIPSETTING(    0x80, DEF_STR( On ) )
  241. INPUT_PORTS_END
  242.  
  243.  
  244.  
  245. static struct GfxLayout toki_charlayout =
  246. {
  247.     8,8,
  248.     4096,
  249.     4,
  250.     { 4096*16*8+0, 4096*16*8+4, 0, 4 },
  251.     { 3, 2, 1, 0, 8+3, 8+2, 8+1, 8+0 },
  252.     { 0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16 },
  253.     16*8
  254. };
  255.  
  256. static struct GfxLayout toki_tilelayout =
  257. {
  258.     16,16,
  259.     4096,
  260.     4,
  261.     { 2*4, 3*4, 0*4, 1*4 },
  262.     { 3, 2, 1, 0, 16+3, 16+2, 16+1, 16+0,
  263.             64*8+3, 64*8+2, 64*8+1, 64*8+0, 64*8+16+3, 64*8+16+2, 64*8+16+1, 64*8+16+0 },
  264.     { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32,
  265.             8*32, 9*32, 10*32, 11*32, 12*32, 13*32, 14*32, 15*32 },
  266.     128*8
  267. };
  268.  
  269. static struct GfxLayout toki_spritelayout =
  270. {
  271.     16,16,
  272.     8192,
  273.     4,
  274.     { 2*4, 3*4, 0*4, 1*4 },
  275.     { 3, 2, 1, 0, 16+3, 16+2, 16+1, 16+0,
  276.             64*8+3, 64*8+2, 64*8+1, 64*8+0, 64*8+16+3, 64*8+16+2, 64*8+16+1, 64*8+16+0 },
  277.     { 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32,
  278.             8*32, 9*32, 10*32, 11*32, 12*32, 13*32, 14*32, 15*32 },
  279.     128*8
  280. };
  281.  
  282. static struct GfxDecodeInfo toki_gfxdecodeinfo[] =
  283. {
  284.     { REGION_GFX1, 0, &toki_charlayout,  16*16, 16 },
  285.     { REGION_GFX2, 0, &toki_spritelayout, 0*16, 16 },
  286.     { REGION_GFX3, 0, &toki_tilelayout,  32*16, 16 },
  287.     { REGION_GFX4, 0, &toki_tilelayout,  48*16, 16 },
  288.     { -1 } /* end of array */
  289. };
  290.  
  291. static struct GfxLayout tokib_charlayout =
  292. {
  293.     8,8,    /* 8 by 8 */
  294.     4096,    /* 4096 characters */
  295.     4,    /* 4 bits per pixel */
  296.     {4096*8*8*3,4096*8*8*2,4096*8*8*1,4096*8*8*0 },    /* planes */
  297.     { 0, 1,  2,  3,  4,  5,  6,  7},        /* x bit */
  298.     { 0, 8, 16, 24, 32, 40, 48, 56},        /* y bit */
  299.     8*8
  300. };
  301.  
  302. static struct GfxLayout tokib_tilelayout =
  303. {
  304.     16,16,    /* 16 by 16 */
  305.     4096,    /* 4096 characters */
  306.     4,    /* 4 bits per pixel */
  307.     { 4096*16*16*3,4096*16*16*2,4096*16*16*1,4096*16*16*0 },    /* planes */
  308.     { 0, 1, 2, 3, 4, 5, 6, 7,
  309.       0x8000*8+0, 0x8000*8+1, 0x8000*8+2, 0x8000*8+3, 0x8000*8+4,
  310.       0x8000*8+5, 0x8000*8+6, 0x8000*8+7 },                /* x bit */
  311.     {
  312.       0,8,16,24,32,40,48,56,
  313.       0x10000*8+ 0, 0x10000*8+ 8, 0x10000*8+16, 0x10000*8+24, 0x10000*8+32,
  314.       0x10000*8+40, 0x10000*8+48, 0x10000*8+56 },            /* y bit */
  315.     8*8
  316. };
  317.  
  318. static struct GfxLayout tokib_spriteslayout =
  319. {
  320.     16,16,    /* 16 by 16 */
  321.     8192,    /* 8192 sprites */
  322.     4,    /* 4 bits per pixel */
  323.     { 8192*16*16*3,8192*16*16*2,8192*16*16*1,8192*16*16*0 },    /* planes */
  324.     {    0,     1,     2,     3,     4,     5,     6,     7,
  325.      128+0, 128+1, 128+2, 128+3, 128+4, 128+5, 128+6, 128+7 },    /* x bit */
  326.     { 0,8,16,24,32,40,48,56,64,72,80,88,96,104,112,120 },        /* y bit */
  327.     16*16
  328. };
  329.  
  330. static struct GfxDecodeInfo tokib_gfxdecodeinfo[] =
  331. {
  332.     { REGION_GFX1, 0, &tokib_charlayout,    16*16, 16 },
  333.     { REGION_GFX2, 0, &tokib_spriteslayout,  0*16, 16 },
  334.     { REGION_GFX3, 0, &tokib_tilelayout,    32*16, 16 },
  335.     { REGION_GFX4, 0, &tokib_tilelayout,    48*16, 16 },
  336.     { -1 } /* end of array */
  337. };
  338.  
  339.  
  340.  
  341. static struct YM3526interface ym3812_interface =
  342. {
  343.     1,            /* 1 chip (no more supported) */
  344.     3600000,    /* 3.600000 MHz ? (partially supported) */
  345.     { 60 }        /* (not supported) */
  346. };
  347.  
  348. static struct MSM5205interface msm5205_interface =
  349. {
  350.     1,                    /* 1 chip             */
  351.     384000,                /* 384KHz             */
  352.     { toki_adpcm_int },/* interrupt function */
  353.     { MSM5205_S96_4B},    /* 4KHz               */
  354.     { 60 }
  355. };
  356.  
  357. static struct MachineDriver machine_driver_toki =
  358. {
  359.     /* basic machine hardware */
  360.     {
  361.         {
  362.             CPU_M68000,
  363.             16000000,    /* with less than 14MHz there are slowdowns and the */
  364.                         /* title screen doesn't wave correctly */
  365.             readmem,writemem,
  366.             0,0,
  367.             toki_interrupt,1
  368.         },
  369.         {
  370.             CPU_Z80 | CPU_AUDIO_CPU,
  371.             4000000,    /* 4 MHz (?) */
  372.             sound_readmem,sound_writemem,
  373.             0,0,
  374.             ignore_interrupt,0    /* IRQs are caused by the main CPU?? */
  375.                                 /* NMIs are caused by the ADPCM chip */
  376.         },
  377.     },
  378.     57, DEFAULT_60HZ_VBLANK_DURATION,    /* frames per second, vblank duration */
  379.     1,    /* 1 CPU slice per frame - interleaving is forced when a sound command is written */
  380.     0,
  381.     /* video hardware */
  382.     32*8, 32*8,
  383.     { 0*8, 32*8-1, 0*8, 32*8-1 },
  384.     toki_gfxdecodeinfo,
  385.     4*256, 4*256,
  386.     0,
  387.     VIDEO_TYPE_RASTER | VIDEO_MODIFIES_PALETTE,
  388.     0,
  389.     toki_vh_start,
  390.     toki_vh_stop,
  391.     toki_vh_screenrefresh,
  392.  
  393.     /* sound hardware */
  394.     0,0,0,0,
  395.     {
  396.         {
  397.             SOUND_YM3812,
  398.             &ym3812_interface
  399.         },
  400.         {
  401.             SOUND_MSM5205,
  402.             &msm5205_interface
  403.         }
  404.     }
  405. };
  406.  
  407. static struct MachineDriver machine_driver_tokib =
  408. {
  409.     /* basic machine hardware */
  410.     {
  411.         {
  412.             CPU_M68000,
  413.             16000000,    /* with less than 14MHz there are slowdowns and the */
  414.                         /* title screen doesn't wave correctly */
  415.             readmem,writemem,
  416.             0,0,
  417.             toki_interrupt,1
  418.         },
  419.         {
  420.             CPU_Z80 | CPU_AUDIO_CPU,
  421.             4000000,    /* 4 MHz (?) */
  422.             sound_readmem,sound_writemem,
  423.             0,0,
  424.             ignore_interrupt,0    /* IRQs are caused by the main CPU?? */
  425.                                 /* NMIs are caused by the ADPCM chip */
  426.         },
  427.     },
  428.     57, DEFAULT_60HZ_VBLANK_DURATION,    /* frames per second, vblank duration */
  429.     1,    /* 1 CPU slice per frame - interleaving is forced when a sound command is written */
  430.     0,
  431.     /* video hardware */
  432.     32*8, 32*8,
  433.     { 0*8, 32*8-1, 0*8, 32*8-1 },
  434.     tokib_gfxdecodeinfo,
  435.     4*256, 4*256,
  436.     0,
  437.     VIDEO_TYPE_RASTER | VIDEO_MODIFIES_PALETTE,
  438.     0,
  439.     toki_vh_start,
  440.     toki_vh_stop,
  441.     toki_vh_screenrefresh,
  442.  
  443.     /* sound hardware */
  444.     0,0,0,0,
  445.     {
  446.         {
  447.             SOUND_YM3812,
  448.             &ym3812_interface
  449.         },
  450.         {
  451.             SOUND_MSM5205,
  452.             &msm5205_interface
  453.         }
  454.     }
  455. };
  456.  
  457.  
  458.  
  459. /***************************************************************************
  460.  
  461.   Game driver(s)
  462.  
  463. ***************************************************************************/
  464.  
  465. ROM_START( toki )
  466.     ROM_REGION( 0x60000, REGION_CPU1 )    /* 6*64k for 68000 code */
  467.     ROM_LOAD_EVEN( "tokijp.006",   0x00000, 0x20000, 0x03d726b1 )
  468.     ROM_LOAD_ODD ( "tokijp.004",   0x00000, 0x20000, 0x54a45e12 )
  469.     ROM_LOAD_EVEN( "tokijp.005",   0x40000, 0x10000, 0xd6a82808 )
  470.     ROM_LOAD_ODD ( "tokijp.003",   0x40000, 0x10000, 0xa01a5b10 )
  471.  
  472.     ROM_REGION( 0x10000, REGION_CPU2 )    /* 64k for code */
  473.     /* is this the Z80 code? maybe its encrypted */
  474.     ROM_LOAD( "tokijp.008",   0x00000, 0x2000, 0x6c87c4c5 )
  475.  
  476.     ROM_REGION( 0x020000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  477.     ROM_LOAD( "tokijp.001",   0x000000, 0x10000, 0x8aa964a2 )    /* chars */
  478.     ROM_LOAD( "tokijp.002",   0x010000, 0x10000, 0x86e87e48 )
  479.  
  480.     ROM_REGION( 0x100000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  481.     ROM_LOAD( "toki.ob1",     0x000000, 0x80000, 0xa27a80ba )    /* sprites */
  482.     ROM_LOAD( "toki.ob2",     0x080000, 0x80000, 0xfa687718 )
  483.  
  484.     ROM_REGION( 0x080000, REGION_GFX3 | REGIONFLAG_DISPOSE )
  485.     ROM_LOAD( "toki.bk1",     0x000000, 0x80000, 0xfdaa5f4b )    /* tiles 1 */
  486.  
  487.     ROM_REGION( 0x080000, REGION_GFX4 | REGIONFLAG_DISPOSE )
  488.     ROM_LOAD( "toki.bk2",     0x000000, 0x80000, 0xd86ac664 )    /* tiles 2 */
  489.  
  490.     ROM_REGION( 0x20000, REGION_SOUND1 )    /* samples */
  491.     ROM_LOAD( "tokijp.009",   0x00000, 0x20000, 0xae7a6b8b )
  492.  
  493.     ROM_REGION( 0x10000, REGION_USER1 )    /* unknown */
  494.     ROM_LOAD( "tokijp.007",   0x00000, 0x10000, 0xa67969c4 )
  495. ROM_END
  496.  
  497. ROM_START( toki2 )
  498.     ROM_REGION( 0x60000, REGION_CPU1 )    /* 6*64k for 68000 code */
  499.     ROM_LOAD_EVEN( "tokijp.006",   0x00000, 0x20000, 0x03d726b1 )
  500.     ROM_LOAD_ODD ( "4c.10k",       0x00000, 0x20000, 0xb2c345c5 )
  501.     ROM_LOAD_EVEN( "tokijp.005",   0x40000, 0x10000, 0xd6a82808 )
  502.     ROM_LOAD_ODD ( "tokijp.003",   0x40000, 0x10000, 0xa01a5b10 )
  503.  
  504.     ROM_REGION( 0x10000, REGION_CPU2 )    /* 64k for code */
  505.     /* is this the Z80 code? maybe its encrypted */
  506.     ROM_LOAD( "tokijp.008",   0x00000, 0x2000, 0x6c87c4c5 )
  507.  
  508.     ROM_REGION( 0x020000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  509.     ROM_LOAD( "tokijp.001",   0x000000, 0x10000, 0x8aa964a2 )    /* chars */
  510.     ROM_LOAD( "tokijp.002",   0x010000, 0x10000, 0x86e87e48 )
  511.  
  512.     ROM_REGION( 0x100000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  513.     ROM_LOAD( "toki.ob1",     0x000000, 0x80000, 0xa27a80ba )    /* sprites */
  514.     ROM_LOAD( "toki.ob2",     0x080000, 0x80000, 0xfa687718 )
  515.  
  516.     ROM_REGION( 0x080000, REGION_GFX3 | REGIONFLAG_DISPOSE )
  517.     ROM_LOAD( "toki.bk1",     0x000000, 0x80000, 0xfdaa5f4b )    /* tiles 1 */
  518.  
  519.     ROM_REGION( 0x080000, REGION_GFX4 | REGIONFLAG_DISPOSE )
  520.     ROM_LOAD( "toki.bk2",     0x000000, 0x80000, 0xd86ac664 )    /* tiles 2 */
  521.  
  522.     ROM_REGION( 0x20000, REGION_SOUND1 )    /* samples */
  523.     ROM_LOAD( "tokijp.009",   0x00000, 0x20000, 0xae7a6b8b )
  524.  
  525.     ROM_REGION( 0x10000, REGION_USER1 )    /* unknown */
  526.     ROM_LOAD( "tokijp.007",   0x00000, 0x10000, 0xa67969c4 )
  527. ROM_END
  528.  
  529. ROM_START( toki3 )
  530.     ROM_REGION( 0x60000, REGION_CPU1 )    /* 6*64k for 68000 code */
  531.     ROM_LOAD_EVEN( "l10_6.bin",    0x00000, 0x20000, 0x94015d91 )
  532.     ROM_LOAD_ODD ( "k10_4e.bin",   0x00000, 0x20000, 0x531bd3ef )
  533.     ROM_LOAD_EVEN( "tokijp.005",   0x40000, 0x10000, 0xd6a82808 )
  534.     ROM_LOAD_ODD ( "tokijp.003",   0x40000, 0x10000, 0xa01a5b10 )
  535.  
  536.     ROM_REGION( 0x10000, REGION_CPU2 )    /* 64k for code */
  537.     /* is this the Z80 code? maybe its encrypted */
  538.     ROM_LOAD( "tokijp.008",   0x00000, 0x2000, 0x6c87c4c5 )
  539.  
  540.     ROM_REGION( 0x020000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  541.     ROM_LOAD( "tokijp.001",   0x000000, 0x10000, 0x8aa964a2 )    /* chars */
  542.     ROM_LOAD( "tokijp.002",   0x010000, 0x10000, 0x86e87e48 )
  543.  
  544.     ROM_REGION( 0x100000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  545.     ROM_LOAD( "toki.ob1",     0x000000, 0x80000, 0xa27a80ba )    /* sprites */
  546.     ROM_LOAD( "toki.ob2",     0x080000, 0x80000, 0xfa687718 )
  547.  
  548.     ROM_REGION( 0x080000, REGION_GFX3 | REGIONFLAG_DISPOSE )
  549.     ROM_LOAD( "toki.bk1",     0x000000, 0x80000, 0xfdaa5f4b )    /* tiles 1 */
  550.  
  551.     ROM_REGION( 0x080000, REGION_GFX4 | REGIONFLAG_DISPOSE )
  552.     ROM_LOAD( "toki.bk2",     0x000000, 0x80000, 0xd86ac664 )    /* tiles 2 */
  553.  
  554.     ROM_REGION( 0x20000, REGION_SOUND1 )    /* samples */
  555.     ROM_LOAD( "tokijp.009",   0x00000, 0x20000, 0xae7a6b8b )
  556.  
  557.     ROM_REGION( 0x10000, REGION_USER1 )    /* unknown */
  558.     ROM_LOAD( "tokijp.007",   0x00000, 0x10000, 0xa67969c4 )
  559. ROM_END
  560.  
  561. ROM_START( tokiu )
  562.     ROM_REGION( 0x60000, REGION_CPU1 )    /* 6*64k for 68000 code */
  563.     ROM_LOAD_EVEN( "6b.10m",       0x00000, 0x20000, 0x3674d9fe )
  564.     ROM_LOAD_ODD ( "14.10k",       0x00000, 0x20000, 0xbfdd48af )
  565.     ROM_LOAD_EVEN( "tokijp.005",   0x40000, 0x10000, 0xd6a82808 )
  566.     ROM_LOAD_ODD ( "tokijp.003",   0x40000, 0x10000, 0xa01a5b10 )
  567.  
  568.     ROM_REGION( 0x10000, REGION_CPU2 )    /* 64k for code */
  569.     /* is this the Z80 code? maybe its encrypted */
  570.     ROM_LOAD( "tokijp.008",   0x00000, 0x2000, 0x6c87c4c5 )
  571.  
  572.     ROM_REGION( 0x020000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  573.     ROM_LOAD( "tokijp.001",   0x000000, 0x10000, 0x8aa964a2 )    /* chars */
  574.     ROM_LOAD( "tokijp.002",   0x010000, 0x10000, 0x86e87e48 )
  575.  
  576.     ROM_REGION( 0x100000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  577.     ROM_LOAD( "toki.ob1",     0x000000, 0x80000, 0xa27a80ba )    /* sprites */
  578.     ROM_LOAD( "toki.ob2",     0x080000, 0x80000, 0xfa687718 )
  579.  
  580.     ROM_REGION( 0x080000, REGION_GFX3 | REGIONFLAG_DISPOSE )
  581.     ROM_LOAD( "toki.bk1",     0x000000, 0x80000, 0xfdaa5f4b )    /* tiles 1 */
  582.  
  583.     ROM_REGION( 0x080000, REGION_GFX4 | REGIONFLAG_DISPOSE )
  584.     ROM_LOAD( "toki.bk2",     0x000000, 0x80000, 0xd86ac664 )    /* tiles 2 */
  585.  
  586.     ROM_REGION( 0x20000, REGION_SOUND1 )    /* samples */
  587.     ROM_LOAD( "tokijp.009",   0x00000, 0x20000, 0xae7a6b8b )
  588.  
  589.     ROM_REGION( 0x10000, REGION_USER1 )    /* unknown */
  590.     ROM_LOAD( "tokijp.007",   0x00000, 0x10000, 0xa67969c4 )
  591. ROM_END
  592.  
  593. ROM_START( tokib )
  594.     ROM_REGION( 0x60000, REGION_CPU1 )    /* 6*64k for 68000 code */
  595.     ROM_LOAD_EVEN( "toki.e3",      0x00000, 0x20000, 0xae9b3da4 )
  596.     ROM_LOAD_ODD ( "toki.e5",      0x00000, 0x20000, 0x66a5a1d6 )
  597.     ROM_LOAD_EVEN( "tokijp.005",   0x40000, 0x10000, 0xd6a82808 )
  598.     ROM_LOAD_ODD ( "tokijp.003",   0x40000, 0x10000, 0xa01a5b10 )
  599.  
  600.     ROM_REGION( 0x18000, REGION_CPU2 )    /* 64k for code + 32k for banked data */
  601.     ROM_LOAD( "toki.e1",      0x00000, 0x8000, 0x2832ef75 )
  602.     ROM_CONTINUE(             0x10000, 0x8000 )    /* banked at 8000-bfff */
  603.  
  604.     ROM_REGION( 0x020000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  605.     ROM_LOAD( "toki.e21",     0x000000, 0x08000, 0xbb8cacbd )    /* chars */
  606.     ROM_LOAD( "toki.e13",     0x008000, 0x08000, 0x052ad275 )
  607.     ROM_LOAD( "toki.e22",     0x010000, 0x08000, 0x04dcdc21 )
  608.     ROM_LOAD( "toki.e7",      0x018000, 0x08000, 0x70729106 )
  609.  
  610.     ROM_REGION( 0x100000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  611.     ROM_LOAD( "toki.e26",     0x000000, 0x20000, 0xa8ba71fc )    /* sprites */
  612.     ROM_LOAD( "toki.e28",     0x020000, 0x20000, 0x29784948 )
  613.     ROM_LOAD( "toki.e34",     0x040000, 0x20000, 0xe5f6e19b )
  614.     ROM_LOAD( "toki.e36",     0x060000, 0x20000, 0x96e8db8b )
  615.     ROM_LOAD( "toki.e30",     0x080000, 0x20000, 0x770d2b1b )
  616.     ROM_LOAD( "toki.e32",     0x0a0000, 0x20000, 0xc289d246 )
  617.     ROM_LOAD( "toki.e38",     0x0c0000, 0x20000, 0x87f4e7fb )
  618.     ROM_LOAD( "toki.e40",     0x0e0000, 0x20000, 0x96e87350 )
  619.  
  620.     ROM_REGION( 0x080000, REGION_GFX3 | REGIONFLAG_DISPOSE )
  621.     ROM_LOAD( "toki.e23",     0x000000, 0x10000, 0xfeb13d35 )    /* tiles 1 */
  622.     ROM_LOAD( "toki.e24",     0x010000, 0x10000, 0x5b365637 )
  623.     ROM_LOAD( "toki.e15",     0x020000, 0x10000, 0x617c32e6 )
  624.     ROM_LOAD( "toki.e16",     0x030000, 0x10000, 0x2a11c0f0 )
  625.     ROM_LOAD( "toki.e17",     0x040000, 0x10000, 0xfbc3d456 )
  626.     ROM_LOAD( "toki.e18",     0x050000, 0x10000, 0x4c2a72e1 )
  627.     ROM_LOAD( "toki.e8",      0x060000, 0x10000, 0x46a1b821 )
  628.     ROM_LOAD( "toki.e9",      0x070000, 0x10000, 0x82ce27f6 )
  629.  
  630.     ROM_REGION( 0x080000, REGION_GFX4 | REGIONFLAG_DISPOSE )
  631.     ROM_LOAD( "toki.e25",     0x000000, 0x10000, 0x63026cad )    /* tiles 2 */
  632.     ROM_LOAD( "toki.e20",     0x010000, 0x10000, 0xa7f2ce26 )
  633.     ROM_LOAD( "toki.e11",     0x020000, 0x10000, 0x48989aa0 )
  634.     ROM_LOAD( "toki.e12",     0x030000, 0x10000, 0xc2ad9342 )
  635.     ROM_LOAD( "toki.e19",     0x040000, 0x10000, 0x6cd22b18 )
  636.     ROM_LOAD( "toki.e14",     0x050000, 0x10000, 0x859e313a )
  637.     ROM_LOAD( "toki.e10",     0x060000, 0x10000, 0xe15c1d0f )
  638.     ROM_LOAD( "toki.e6",      0x070000, 0x10000, 0x6f4b878a )
  639. ROM_END
  640.  
  641.  
  642.  
  643. void init_tokib(void)
  644. {
  645.     unsigned char *temp = malloc (65536 * 2);
  646.     int i, offs;
  647.  
  648.     /* invert the sprite data in the ROMs */
  649.     for (i = 0; i < memory_region_length(REGION_GFX2); i++)
  650.         memory_region(REGION_GFX2)[i] ^= 0xff;
  651.  
  652.     /* merge background tile graphics together */
  653.     if (temp)
  654.     {
  655.         for (offs = 0; offs < memory_region_length(REGION_GFX3); offs += 0x20000)
  656.         {
  657.             unsigned char *base = &memory_region(REGION_GFX3)[offs];
  658.             memcpy (temp, base, 65536 * 2);
  659.             for (i = 0; i < 16; i++)
  660.             {
  661.                 memcpy (&base[0x00000 + i * 0x800], &temp[0x0000 + i * 0x2000], 0x800);
  662.                 memcpy (&base[0x10000 + i * 0x800], &temp[0x0800 + i * 0x2000], 0x800);
  663.                 memcpy (&base[0x08000 + i * 0x800], &temp[0x1000 + i * 0x2000], 0x800);
  664.                 memcpy (&base[0x18000 + i * 0x800], &temp[0x1800 + i * 0x2000], 0x800);
  665.             }
  666.         }
  667.         for (offs = 0; offs < memory_region_length(REGION_GFX4); offs += 0x20000)
  668.         {
  669.             unsigned char *base = &memory_region(REGION_GFX4)[offs];
  670.             memcpy (temp, base, 65536 * 2);
  671.             for (i = 0; i < 16; i++)
  672.             {
  673.                 memcpy (&base[0x00000 + i * 0x800], &temp[0x0000 + i * 0x2000], 0x800);
  674.                 memcpy (&base[0x10000 + i * 0x800], &temp[0x0800 + i * 0x2000], 0x800);
  675.                 memcpy (&base[0x08000 + i * 0x800], &temp[0x1000 + i * 0x2000], 0x800);
  676.                 memcpy (&base[0x18000 + i * 0x800], &temp[0x1800 + i * 0x2000], 0x800);
  677.             }
  678.         }
  679.  
  680.         free (temp);
  681.     }
  682. }
  683.  
  684.  
  685.  
  686. GAMEX( 1989, toki,  0,    toki,  toki, 0,     ROT0, "Tad", "Toki (set 1)", GAME_NOT_WORKING | GAME_NO_COCKTAIL )
  687. GAMEX( 1989, toki2, toki, toki,  toki, 0,     ROT0, "Tad", "Toki (set 2)", GAME_NOT_WORKING | GAME_NO_COCKTAIL )
  688. GAMEX( 1989, toki3, toki, toki,  toki, 0,     ROT0, "Tad", "Toki (set 3)", GAME_NOT_WORKING | GAME_NO_COCKTAIL )
  689. GAMEX( 1989, tokiu, toki, toki,  toki, 0,     ROT0, "Tad (Fabtek license)", "Toki (US)", GAME_NOT_WORKING | GAME_NO_COCKTAIL )
  690. GAMEX( 1989, tokib, toki, tokib, toki, tokib, ROT0, "bootleg", "Toki (bootleg)", GAME_NO_COCKTAIL )
  691.